package com.css.zfzx.sjcj.modules.jobschedule.entity.enums;

import com.css.bpm.platform.utils.PlatformObjectUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>地震行业普查任务完成情况进度</p>
 *
 * @author liuhy
 * @date 2021/8/17
 */
public enum ScheduleReportEnum {

    EQ("41", "地震", "f6769e28-e6aa-47b3-8ff5-f7b8163ae5a2"),
    building_sampling_survey("41-1", "房屋抽样调查", "b338f30d-c33b-49ae-b051-9b5b95e0784c"),
    seismically_active_fault_db_construction("41-2", "现有地震活断层数据库建设(活断层线)", "4108998f-24cf-4fc6-b322-d92e46228654"),
    country_level_active_fault_distribution1_5w("41-3", "编制县级1:5万活动断层分布图", "49c37732-0666-4950-ba57-ab35d6824829"),
    country_level_description_of_active_fault_distribution1_5w("41-6", "编制县级1:5万活动断层分布图说明书", ""),
    country_level_report_of_active_fault_distribution_map("41-7", "编制县级1:5万活动断层分布图成果报告", ""),
    drilling_for_seismic_engineering_geological_conditions("41-4", "地震工程地质条件钻孔基础数据库建设", "bc9a0c40-340e-4a67-ac30-6cf598d5e4e5"),
    seismometer_map_1_25("41-5", "编制1:25万地震构造图", "81a5b7bb-a53f-459f-a2f2-e8c581e57993"),
    description_of_seismic_tectonic_map_1_25w("41-8", "编制1：25万地震构造图说明书", ""),
    report_on_seismometer_map_results_1_25w("41-9", "编制1：25万地震构造图成果报告", ""),
    PGA_contour_map_of_ground_motion("41-10", "地震动PGA等值线图", ""),
    seismic_hazard_level_map_vector_points("41-11", "地震危险性等级图（矢量点）", ""),
    seismic_hazard_level_map_vector_plane("41-12", "地震危险性等级图（矢量面）", ""),
    building_seismic_hazard_assessment_map("41-13", "房屋建筑物地震隐患评估图完成数量（个）", ""),
    seismic_hazard_assessment_map_of_municipal_bridges("41-14", "市政桥梁地震隐患评估图", ""),
    earthquake_hazard_assessment_map_of_urban_waterworks("41-15", "城市自来水厂地震隐患评估图", ""),
    EDP_region_map_priority_of_seismic_reinforcement("41-16", "地震灾害防治区划图（抗震加固优先级）", ""),
    EDP_region_map_active_fault_101m_avoidance_buffer("41-17", "地震灾害防治区划图（活动断层101m避让缓冲区）", ""),
    EDP_region_map_active_fault_201m_avoidance_buffer("41-18", "地震灾害防治区划图（活动断层201m避让缓冲区）", ""),
    location_error_of_active_fault("41-19", "活动断层位置误差", ""),
    housing_direct_economic_loss_level_diagram_50_years_63p("41-20", "50年超越概率63%地震作用下房屋直接经济损失等级图", ""),
    housing_direct_economic_loss_level_diagram_50_years_10p("41-21", "50年超越概率10%地震作用下房屋直接经济损失等级图", ""),
    housing_direct_economic_loss_level_diagram_50_years_2p("41-22", "50年超越概率2%地震作用下房屋直接经济损失等级图", ""),
    housing_direct_economic_loss_level_diagram_100_years_1p("41-23", "100年超越概率1%地震作用下房屋直接经济损失等级图", ""),

    death_population_rating_chart_50_years_63p("41-24", "50年超越概率63%地震作用下房屋破坏导致的死亡人口等级图", ""),
    death_population_rating_chart_50_years_10p("41-25", "50年超越概率10%地震作用下房屋破坏导致的死亡人口等级图", ""),
    death_population_rating_chart_50_years_2p("41-26", "50年超越概率2%地震作用下房屋破坏导致的死亡人口等级图", ""),
    death_population_rating_chart_100_years_1p("41-27", "100年超越概率1%地震作用下房屋破坏导致的死亡人口等级图", ""),

    housing_direct_economic_damage_assessment_50_years_63p("41-28", "50年超越概率63%地震作用下房屋直接经济损失评估图", ""),
    housing_direct_economic_damage_assessment_50_years_10p("41-29", "50年超越概率10%地震作用下房屋直接经济损失评估图", ""),
    housing_direct_economic_damage_assessment_50_years_2p("41-30", "50年超越概率2%地震作用下房屋直接经济损失评估图", ""),
    housing_direct_economic_damage_assessment_100_years_1p("41-31", "100年超越概率1%地震作用下房屋直接经济损失评估图", ""),

    death_population_assessment_chart_50_years_63p("41-32", "50年超越概率63%地震作用下房屋破坏导致的死亡人口评估图", ""),
    death_population_assessment_chart_50_years_10p("41-33", "50年超越概率10%地震作用下房屋破坏导致的死亡人口评估图", ""),
    death_population_assessment_chart_50_years_2p("41-34", "50年超越概率2%地震作用下房屋破坏导致的死亡人口评估图", ""),
    death_population_assessment_chart_100_years_1p("41-35", "100年超越概率1%地震作用下房屋破坏导致的死亡人口评估图", ""),
    ;
    private String taskId;
    private String taskName;
    private String reportId;

    private final static Map<String, String> name2Code;
    private final static Map<String, String> name2ReportId;

    static {
        name2Code = Arrays.stream(values()).collect(Collectors.toMap(ScheduleReportEnum::getTaskName, ScheduleReportEnum::getTaskId));
        name2ReportId = new HashMap<>(6);
        Arrays.stream(values()).forEach(e -> {
            if (PlatformObjectUtils.isNotEmpty(e.getReportId()))
                name2ReportId.put(e.getTaskName(), e.getReportId());
        });
    }

    /**
     * 根据任务名称获取任务编码
     *
     * @param taskName 任务名称
     * @return 任务编码
     */
    public static String getTaskCode(String taskName) {
        if (name2Code == null)
            return "";
        return name2Code.get(taskName);
    }

    /**
     * 根据任务名称获取任务对象(枚举实例)
     *
     * @param taskId
     * @return
     */
    public static ScheduleReportEnum getById(String taskId) {
        for (ScheduleReportEnum menu : ScheduleReportEnum.values()) {
            if (menu.getTaskId().equals(taskId)) {
                return menu;
            }
        }
        return null;
    }

    /**
     * 得到所有需要上报的任务集合
     */
    public static List<ScheduleReportEnum> getReportList() {
        List<ScheduleReportEnum> scheduleReportEnums = new ArrayList<>();
        for (ScheduleReportEnum menu : ScheduleReportEnum.values()) {
            if (StringUtils.isNotEmpty(menu.getReportId()) && !"".equals(menu.getReportId())) {
                scheduleReportEnums.add(menu);
            }
        }
        return scheduleReportEnums;
    }

    /**
     * 根据任务名称获取reportId
     *
     * @param taskName 任务名称
     * @return 空 -> 该任务不需要上报，没有reportId,
     * reportId -> 接收方定义的上报ID
     */
    public static String getReportId(String taskName) {
        if (name2ReportId == null)
            return null;
        return name2ReportId.get(taskName);
    }

    ScheduleReportEnum(String taskId, String taskName, String reportId) {
        this.taskId = taskId;
        this.taskName = taskName;
        this.reportId = reportId;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getTaskName() {
        return taskName;
    }

    public void setTaskName(String taskName) {
        this.taskName = taskName;
    }

    public String getReportId() {
        return reportId;
    }

    public void setReportId(String reportId) {
        this.reportId = reportId;
    }

}
